home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / GETS.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  111 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8.         extrn    sl_putc:far, sl_getc:far
  9. ;
  10. ;
  11. ; GETS-    Reads a line of text from the user and stores the characters into
  12. ;    the buffer pointed at by ES:DI.  The string must be large enough
  13. ;    to hold the result.
  14. ;
  15. ;    The returned string is zero terminated and does not include the
  16. ;    carriage return (ENTER) key code.
  17. ;
  18. ; Released to the public domain.
  19. ; Created by: Randall Hyde
  20. ; Date: 10/5/91
  21. ; Updates:
  22. ;
  23. ;    10/5/91-    Modified original GETS (GETSM) routine to produce
  24. ;            this one.
  25. ;
  26. ;
  27. ;
  28. ;
  29.         public    sl_gets
  30. sl_gets        proc    far
  31.         push    es
  32.         push    ax
  33.         push    bx
  34.         push    cx
  35.         push    di
  36.         pushf
  37. ;
  38. ; Read data from keyboard until the user hits the enter key.
  39. ;
  40.         xor    bx, bx
  41. RdKbdLp:    call    sl_getc
  42.         jc    BadGetc
  43.         cmp    ah, 0
  44.         jz    EndString
  45.         cmp    al, 0                ;Scan code?
  46.         jnz    GotKey                ;If so, ignore it.
  47.         call    sl_getc
  48.         jmp    RdKbdLp
  49. ;
  50. GotKey:        cmp    al, 08                ;Backspace
  51.         jne    NotBS
  52.         or    bx, bx                 ;Don't do it if at
  53.         jz    RdKbdLp                ; beginning of line.
  54.         dec    bx
  55.         call    sl_putc
  56.         jmp    RdKbdLp
  57. ;
  58. NotBS:        cmp    al, 13                ;See if ENTER.
  59.         jnz    NotCR
  60.         call    sl_putc
  61.         mov    al, 0ah
  62.         call    sl_putc
  63.         mov    byte ptr es:[bx][di], 0
  64.         inc    bx
  65.         jmp    GetsDone
  66. ;
  67. NotCR:        cmp    al, 1bh                ;ESC
  68.         jne    NotESC
  69.         mov    al, 8
  70. EraseLn:    call    sl_putc
  71.         dec    bx
  72.         jne    EraseLn
  73.         jmp    RdKbdLp
  74. ;
  75. NotESC:        mov    es:[bx][di], al
  76.         call    sl_putc
  77.         inc    bx
  78.         cmp    bx, 255
  79.         jb    RdKbdLp
  80.         mov    al, 7                ;Bell
  81.         call    sl_putc
  82.         dec    bx
  83.         jmp    RdKbdLp
  84. ;
  85. ; Deallocate any left over storage:
  86. ;
  87. GetsDone:    popf
  88.         clc
  89.         pop    di
  90.         pop     cx
  91.         pop    bx
  92.         pop    ax
  93.         pop    es
  94.         ret
  95. ;
  96. EndString:    mov    ax, 0            ;End of file.
  97.         jmp    short BadGetc
  98. ;
  99. BadGets:    mov    ax, 1            ;Memory allocation error.
  100. BadGetc:    popf
  101.         pop    di
  102.         pop    cx
  103.         pop    bx
  104.         add    sp, 2            ;Don't restore AX.
  105.         pop    es
  106.         stc                ;Pass error status.
  107.         ret
  108. sl_gets        endp
  109. stdlib        ends
  110.         end
  111.